package cn.iocoder.yudao.module.system.repository.mybatis.dao.tenant;

import cn.iocoder.yudao.common.pojo.PageResult;
import cn.iocoder.yudao.core.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.core.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.repository.mybatis.domain.tenant.Tenant;
import cn.iocoder.yudao.module.system.vo.tenant.tenant.TenantExportReqVO;
import cn.iocoder.yudao.module.system.vo.tenant.tenant.TenantPageReqVO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 租户 Mapper
 */
@Mapper
public interface TenantMapper extends BaseMapperX<Tenant> {

    default PageResult<Tenant> selectPage(TenantPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<Tenant>()
                .likeIfPresent(Tenant::getName, reqVO.getName())
                .likeIfPresent(Tenant::getContactName, reqVO.getContactName())
                .likeIfPresent(Tenant::getContactMobile, reqVO.getContactMobile())
                .eqIfPresent(Tenant::getStatus, reqVO.getStatus())
                .betweenIfPresent(Tenant::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(Tenant::getId));
    }

    default List<Tenant> selectList(TenantExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<Tenant>()
                .likeIfPresent(Tenant::getName, reqVO.getName())
                .likeIfPresent(Tenant::getContactName, reqVO.getContactName())
                .likeIfPresent(Tenant::getContactMobile, reqVO.getContactMobile())
                .eqIfPresent(Tenant::getStatus, reqVO.getStatus())
                .betweenIfPresent(Tenant::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(Tenant::getId));
    }

    default Tenant selectByName(String name) {
        return selectOne(Tenant::getName, name);
    }

    default Long selectCountByPackageId(Long packageId) {
        return selectCount(Tenant::getPackageId, packageId);
    }

    default List<Tenant> selectListByPackageId(Long packageId) {
        return selectList(Tenant::getPackageId, packageId);
    }

}
